package com.kc.web.controller.business;

import com.kc.business.domain.BizGoodsBuybackOrder;
import com.kc.business.service.IBizGoodsBuybackOrderService;
import com.kc.common.annotation.Log;
import com.kc.common.annotation.RepeatSubmit;
import com.kc.common.core.controller.BaseController;
import com.kc.common.core.domain.AjaxResult;
import com.kc.common.core.page.TableDataInfo;
import com.kc.common.enums.BusinessType;
import com.kc.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * TODO
 *
 * @author zhangshuo
 * @version 1.0
 * @date 2020/10/13
 */
@RestController
@RequestMapping("/business/goodsBuybackOrder")
public class BizGoodsBuybackOrderController extends BaseController {
    @Resource
    IBizGoodsBuybackOrderService buybackOrderService;

    /**
     * 回购商品列表
     *
     * @param buybackOrder
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:goodsBuybackOrder:list')")
    @GetMapping("/list")
    public TableDataInfo getList(BizGoodsBuybackOrder buybackOrder) {
        startPage();
        List<BizGoodsBuybackOrder> orderList = buybackOrderService.getList(buybackOrder);
        for (BizGoodsBuybackOrder order : orderList) {
            order.setImgList(StringUtils.split(order.getImgs(), ","));
        }
        return getDataTable(orderList);
    }

    @PreAuthorize("@ss.hasPermi('business:goodsBuybackOrder:edit')")
    @Log(title = "回购商品管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @RepeatSubmit
    public AjaxResult edit(@Validated @RequestBody BizGoodsBuybackOrder buybackOrder) {
        return toAjax(buybackOrderService.edit(buybackOrder));
    }

    @PreAuthorize("@ss.hasPermi('business:goodsBuybackOrder:confirmReceipt')")
    @Log(title = "确认收货", businessType = BusinessType.UPDATE)
    @PutMapping("/confirmReceipt/{orderId}")
    @RepeatSubmit
    public AjaxResult confirmReceipt(@Validated @PathVariable Integer orderId) {
        BizGoodsBuybackOrder buybackOrder = new BizGoodsBuybackOrder();
        buybackOrder.setOrderId(orderId);
        buybackOrder.setStatus("4");
        return toAjax(buybackOrderService.confirmReceipt(buybackOrder));
    }
}
